package cn.wolfcode.qo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;
@Setter
@Getter
@ToString
public class PageResult<T> {
    private int currentPage;
    private int pageSize;

    private List<T> listData;
    private int totalCount;

    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage, int pageSize, List<T> listData, int totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.listData = listData;
        this.totalCount = totalCount;


        if (totalCount<=pageSize){
            this.totalPage=1;
            this.prevPage=1;
            this.nextPage=1;
        }


        this.totalPage=this.totalCount%this.pageSize==0?
                this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;

        this.nextPage=this.currentPage+1>=this.totalPage?this.totalPage:this.currentPage+1;

        this.prevPage=this.currentPage-1<=1?1:this.currentPage-1;

    }
}
